package com.ikun.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.ikun.entity.Properties;
import com.ikun.service.BuildingsService;
import com.ikun.service.PropertiesService;
import com.ikun.util.Result;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * @ClassName: PropertyController
 * @Author: 吴思伟
 * @CreateTime: 2025-03-26 10:08
 * @Description: 管理员房产管理相关
 */

@Controller
@RequestMapping("/admin/property")
@Tag(name = "房产管理相关", description = "房产管理相关")
public class PropertiesController {

    @Autowired
    private PropertiesService propertyService;

    @Autowired
    private BuildingsService buildingsService;

    /**
     * 展示小区内所有楼房数据（含管家信息）
     *
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    @Tag(name = "查询所有房产", description = "房产管理相关")
    public Result showAllProperty() {
        return Result.success(propertyService.findAll());
    }

    @PutMapping("/manager")
    @ResponseBody
    public Result updateManager(String buildingId, String managerId) {
        int i = propertyService.updateManager(buildingId, managerId);
        if (i == 0) {
            return Result.error("更改失败!");
        } else {
            return Result.success("管家更改成功!");
        }
    }

    @GetMapping("/count")
    @ResponseBody
    public Result showCountAllProperties() {
        return Result.success(propertyService.countAllProperties());
    }

    @GetMapping("/my-info")
    @ResponseBody
    public Result showmyinfoAllProperties() {
        return Result.success(propertyService.showmyinfoAllProperties());
    }

    @PostMapping("/add")
    @ResponseBody
    @Operation(summary = "添加房产信息")
    public Result addProperty(@RequestBody Properties properties) {
        int i = propertyService.addProperty(properties);
        if (i == 0) {
            return Result.error("添加失败!");
        } else {
            return Result.success("添加成功!");
        }
    }

    @PostMapping("/addBuilding")
    @ResponseBody
    @Operation(summary = "添加楼栋信息")
    public Result addBuilding(String buildingNumber, String totalFloors, String totalAreas, String location) {
        return buildingsService.addBuilding(buildingNumber, totalFloors, totalAreas, location);
        // if (i == 0) {
        // return Result.error("添加失败!");
        // } else {
        // return Result.success("添加成功!");
        // }
    }

}
